<template>
  <div class="tab_control">
    <div v-for="(item,state) in titles"
         :key="state"
         class="tabControl_item"
         :class="{active: state===recordState}"
         @click="itemClick(state)">
      <span>{{item}}</span>
    </div>
  </div>
</template>

<script>
  export default {
    name: "TabControl",
    props: {
      titles: {
        type: Array,
        default() {
          return []
        }
      }
    },
    data() {
      return {
        recordState: 0
      }
    },
    methods: {
      itemClick(state) {
        this.recordState=state;
        //将点击的结果传出去：内部往外部传用$emit()；外部往内部传用$promise()
        this.$emit('tabClick',state);
      }
    }
  }
</script>

<style scoped>
  .tab_control {
    display: flex;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    height: 40px;
    line-height: 40px;
    background-color: #fff;
  }
  .tabControl_item {
    flex: 1;
  }
  .tabControl_item span {
    padding: 5px 8px;
  }
  .active {
    color: var(--color-high-text);
  }
  .active span {
    border-bottom: 4px solid var(--color-tint);
  }
</style>
